package com.fr.chart.legend;

import com.fr.base.XMLable;
import com.fr.base.background.Background;
import com.fr.base.core.GraphHelper;
import com.fr.base.core.json.JSONException;
import com.fr.base.core.json.JSONObject;
import com.fr.base.xml.BaseXMLUtils;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.chart.base.equals.Equals;
import com.fr.chart.core.ChartUtils;
import com.fr.chart.marker.Marker;
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Composite;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Paint;
import java.awt.Rectangle;

public class LineMarkerIcon
  implements XMLable
{
  private static final long serialVersionUID = -888457366895932017L;
  public static final String XML_TAG = "LineMarkerIcon";
  private Background background;
  private Color color;
  private int lineStyle = 0;
  private Marker marker = null;
  private float alpha = 1.0F;

  public LineMarkerIcon()
  {
  }

  public LineMarkerIcon(Color paramColor, int paramInt, Marker paramMarker)
  {
    setColor(paramColor);
    setLineStyle(paramInt);
    setMarker(paramMarker);
  }

  public void setAlpha(float paramFloat)
  {
    this.alpha = paramFloat;
  }

  public float getAlpha()
  {
    return this.alpha;
  }

  public void setColor(Color paramColor)
  {
    this.color = paramColor;
  }

  public Color getColor()
  {
    return this.color;
  }

  public void setMarker(Marker paramMarker)
  {
    this.marker = paramMarker;
  }

  public Marker getMarker()
  {
    return this.marker;
  }

  public void setBackground(Background paramBackground)
  {
    this.background = paramBackground;
  }

  public Background getBackground()
  {
    return this.background;
  }

  public void setLineStyle(int paramInt)
  {
    this.lineStyle = paramInt;
  }

  public int getLineStyle()
  {
    return this.lineStyle;
  }

  public void paint(Graphics paramGraphics, int paramInt)
  {
    Graphics2D localGraphics2D = (Graphics2D)paramGraphics;
    Paint localPaint = localGraphics2D.getPaint();
    if (getColor() != null)
      localGraphics2D.setPaint(getColor());
    Composite localComposite = localGraphics2D.getComposite();
    localGraphics2D.setComposite(AlphaComposite.getInstance(3, this.alpha));
    int i = 1;
    if (getLineStyle() != 0)
    {
      GraphHelper.drawLine(localGraphics2D, 0.0D, paramInt / 2.0D, paramInt, paramInt / 2.0D, getLineStyle());
      i = 0;
    }
    if (getMarker() != null)
    {
      getMarker().paint(localGraphics2D, paramInt / 2.0D, paramInt / 2.0D);
      i = 0;
    }
    if (i != 0)
    {
      if (getColor() != null)
        localGraphics2D.fill(new Rectangle(0, 0, paramInt, paramInt));
      if (this.background != null)
        this.background.paint(localGraphics2D, new Rectangle(0, 0, paramInt, paramInt));
    }
    localGraphics2D.setComposite(localComposite);
    localGraphics2D.setPaint(localPaint);
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    if (paramXMLableReader.isChildNode())
    {
      String str1 = paramXMLableReader.getTagName();
      if (str1.equals("Attr"))
      {
        String str2;
        if ((str2 = paramXMLableReader.getAttr("alpha")) != null)
          setAlpha(Float.valueOf(str2).floatValue());
        if ((str2 = paramXMLableReader.getAttr("color")) != null)
          setColor(new Color(Integer.parseInt(str2), true));
        if ((str2 = paramXMLableReader.getAttr("lineStyle")) != null)
          setLineStyle(Integer.parseInt(str2));
      }
      else if (str1.equals("Background"))
      {
        this.background = BaseXMLUtils.readBackground(paramXMLableReader);
      }
      else if (str1.equals("Marker"))
      {
        setMarker(BaseXMLUtils.readMarker(paramXMLableReader));
      }
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    paramXMLPrintWriter.startTAG("LineMarkerIcon");
    paramXMLPrintWriter.startTAG("Attr").attr("alpha", getAlpha());
    if (getColor() != null)
      paramXMLPrintWriter.attr("color", getColor().getRGB());
    paramXMLPrintWriter.attr("lineStyle", getLineStyle());
    paramXMLPrintWriter.end();
    if (getBackground() != null)
      BaseXMLUtils.writeBackground(paramXMLPrintWriter, getBackground());
    if (getMarker() != null)
      BaseXMLUtils.writeMarker(paramXMLPrintWriter, getMarker());
    paramXMLPrintWriter.end();
  }

  public boolean equals(Object paramObject)
  {
    if (!(paramObject instanceof LineMarkerIcon))
      return false;
    LineMarkerIcon localLineMarkerIcon = (LineMarkerIcon)paramObject;
    if (localLineMarkerIcon.getAlpha() != getAlpha())
      return false;
    if (localLineMarkerIcon.getLineStyle() != getLineStyle())
      return false;
    if (!(Equals.equals(localLineMarkerIcon.color, this.color)))
      return false;
    if (!(Equals.equals(localLineMarkerIcon.marker, this.marker)))
      return false;
    return (Equals.equals(localLineMarkerIcon.background, this.background));
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    LineMarkerIcon localLineMarkerIcon = new LineMarkerIcon();
    return localLineMarkerIcon;
  }

  public JSONObject toJSONObject()
    throws JSONException
  {
    JSONObject localJSONObject = new JSONObject();
    localJSONObject.put("color", ChartUtils.color2JS(this.color));
    localJSONObject.put("lineStyle", this.lineStyle);
    localJSONObject.put("alpha", this.alpha);
    if (this.marker != null)
    {
      localJSONObject.put("markerType", this.marker.getMarkerType());
      localJSONObject.put("marker", this.marker.toJSONObject());
    }
    if (this.background != null)
    {
      localJSONObject.put("backgroundType", this.background.getBackgroundType());
      localJSONObject.put("background", this.background.toJSONObject());
    }
    return localJSONObject;
  }
}